import { IFeidaoAiNodejsComponent } from '@dfeidao/atom-nodejs/interfaces';
import nodejs from '@dfeidao/atom-nodejs/msg/nodejs';
// import whoami from '@dfeidao/atom-nodejs/msg/whoami';
import render from '@dfeidao/atom-nodejs/render/render';
import format from '@dfeidao/atom-web/dt/format';
import set from '@dfeidao/atom-web/global/set';
import p001 from './p001';
import p002 from './p002';
import p003 from './p003';
import p004 from './p004';
import p006 from './p006';
// import whoami from '@dfeidao/atom-nodejs/msg/whoami';
export default async function na001(fd: IFeidaoAiNodejsComponent) {
	// todo
	// 获取当前登录的用户信息
	//  const user = await whoami(fd.data.actionid, fd.data.sessionid);
	// const users = await get_params(fd.data.msg, fd.data.headers, user.productid, '3');
	const staff_no = 'YG00000060';
	const staff_name = '庄开局';
	//  console.log(staff_no);
	// const staff_no = user.usercode;
	// const staff_name = user.user_name;
	//  console.log(user);
	const res = await nodejs<Array<{ meeting_no: string }>>(fd.data.actionid, fd.data.sessionid, 'meeting-management/zj-000001/s001', {
		filter: {
			staff_no
		}
	});
	// 取出来meeting_no 的所有值存储到arr中
	const arr = Array();
	for (let i = 0; i < res.length; i++) {
		arr.push(res[i].meeting_no);
	}
	const dt = await nodejs<{ dt: Array<{ meeting_no: string, meeting_name: string, start_time: number, conference_theme: string, meeting_status: string, sponsor: string, meeting_address: string }>; c: number }>(fd.data.actionid, fd.data.sessionid, 'meeting-management/zj-000001/s002', {
		filter: {
			meeting_nos: arr,
			pn: 1
		}
	});

	if (dt.dt.length > 0) {

	}
	const d = dt.dt.map((n) => {
		// 0 不显示时分秒 1 显示秒  2 不显示秒
		return { ...n, start_time: format(n.start_time, 0) };
	});
	for (let j = 0; j < d.length; j++) {
		if (d[j].meeting_status === "1") {
			d[j].meeting_status = '进行中';
		} else if (d[j].meeting_status === "2") {
			d[j].meeting_status = '未解决';
		} else if (d[j].meeting_status === "3") {
			d[j].meeting_status = '完成';
		}
}
	if (dt.dt.length > 0) {
		render(fd.data.node, d, p001, 'p001');
	}
	if (dt.c >= 20) {
		render(fd.data.node, dt.c, p003, 'p003');
	}
	if (dt.dt.length === 0) {
		render(fd.data.node, '', p002, 'p002');
	}
	const dt1 = await nodejs<{ dt: Array<{ meeting_no: string, meeting_name: string, start_time: number, conference_theme: string, meeting_status: string, sponsor: string, meeting_address: string }>; c: number }>(fd.data.actionid, fd.data.sessionid, 'meeting-management/zj-000001/s003', {
		filter: {
			meeting_nos: staff_no,
			pn: 1
		}
	});
	const d1 = dt1.dt.map((n) => {
		// 0 不显示时分秒 1 显示秒  2 不显示秒
		return { ...n, start_time: format(n.start_time,0)};
	});
	for (let j = 0; j < d1.length; j++) {
		if (d1[j].meeting_status === "1") {
			d1[j].meeting_status = '进行中';
		} else if (d1[j].meeting_status === "2") {
			d1[j].meeting_status = '未解决';
		} else if (d1[j].meeting_status === "3") {
			d1[j].meeting_status = '完成';
		}
}
	if (dt1.dt.length > 0) {
		render(fd.data.node, d1, p004, 'p004');
	}
	if (dt1.c >= 20) {
		render(fd.data.node, dt1.c, p006, 'p006');
	}
	if (dt1.c === 0) {
		render(fd.data.node, '', p002, 'p002');
	}
	set('staff_no', staff_no);
	set('staff_name', staff_name);
}
